﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DaInterFace;
using DaInterFace.PDA;
namespace P01
{
    /// <summary>
    /// 设置采购收料磁卡信息
    /// </summary>
    public class A02 : IPDAChild
    {
        public void Code(IPDA handler, CodeResult CR, PDACodeUser user, String parameter)
        {
            P01A02P P = (P01A02P)handler.SerialApi.Deserialize(typeof(P01A02P), parameter, CR.SerialType);

            try
            {
                SqlParameter[] sps = new SqlParameter[9];
                sps[0] = new SqlParameter("@FID", SqlDbType.NVarChar, 50);
                sps[0].Value = P.BillID;
                sps[1] = new SqlParameter("@Note", SqlDbType.NVarChar, 255);
                sps[1].Value = P.Note;
                sps[2] = new SqlParameter("@Address", SqlDbType.NVarChar, 50);
                sps[2].Value = P.Address;
                sps[3] = new SqlParameter("@MeterType", SqlDbType.Int);
                sps[3].Value = P.MeterType;
                sps[4] = new SqlParameter("@RedQty", SqlDbType.Decimal);
                sps[4].Value = P.RedQty;
                sps[5] = new SqlParameter("@RedStyle", SqlDbType.Int);
                sps[5].Value = P.RedStyle;
                sps[6] = new SqlParameter("@RedReason", SqlDbType.NVarChar, 255);
                sps[6].Value = P.RedReason;
                sps[7] = new SqlParameter("@Checker", SqlDbType.NVarChar, 50);
                sps[7].Value = P.Checker;
                sps[8] = new SqlParameter("@UnloadStyle", SqlDbType.NVarChar, 50);
                sps[8].Value = P.UnloadStyle;

                String sql = "UPDATE KEW_PurchInfo SET FNOTE=@Note,FText13=@Address,FComboBox2=@MeterType,FDecimal17=@RedQty,FComboBox4=@RedStyle,FText10=@RedReason,FText9=@Checker,FComboBox3=@UnloadStyle WHERE FID=@FID";
                Recordset rs = handler.Data.ExeProcedure(P.AccountNo, sql, sps);

                if (rs.Enable)
                {
                    CR.Result = EnumResult.Normal;
                    CR.Message = String.Format("操作员{0}对单据{1}进行了收料确认操作", user.UserName, P.BillNo);
                }
                else
                {
                    CR.Result = EnumResult.Error;
                    CR.Message = "数据库错误";
                }
            }
            catch (Exception ex)
            {
                CR.Result = EnumResult.Error;
                CR.Message = String.Format("发生错误:{0}", ex.Message);
            }
        }
    }

    public class P01A02P
    {
        public String AccountNo;
        public String BillID;
        public String BillNo;
        public Decimal RedQty;
        public int RedStyle;
        public String RedReason;
        /// <summary>
        /// 卸货方式
        /// </summary>
        public String UnloadStyle;
        public String Address;
        public String Checker;
        /// <summary>
        /// 过磅类型
        /// </summary>
        public int MeterType;
        /// <summary>
        /// 备注
        /// </summary>
        public String Note;
        /// <summary>
        /// 抽样编号
        /// </summary>
        public String SampNo;
    }
}
